package UILayer;
import CtrLayer.DiscountCtr;
import ModelLayer.PickupDiscount;
import ModelLayer.CustomerDiscount;


/**
 * Write a description of class DiscountUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DiscountUI extends InOut
{
    public static DiscountCtr discountCtr = new DiscountCtr();

    public DiscountUI()
    {
    
    }
    
    public void discountMenu()
    {
        String[] discountMenu = {"Discount Menu", "Add Customer Discount", "Show Customer Discount", "Remove Customer Discount", "Add Pickup Discount", "Show Pickup Discount"};
        printMenu(discountMenu);
    }

    public void start()
    {
        boolean exit = false;
        while(!exit)
        {
            erase(1);
            discountMenu();
            int choice = inputInt("Choose: ");
            erase(1);
            switch(choice)
            {
                case 1 : {setCustomerDiscount();}break;
                case 2 : {getCustomerDiscount();}break;
                case 3 : {removeDiscount();}break;
                case 4 : {setPickupDiscount();}break;
                case 5 : {getPickupDiscount();}break;

                default : {writeEnd();exit=true;}break;
            }
            waitK();
        }
    }
    
    public void setCustomerDiscount()
    {
        if(!haveAccess()) return;
        String type = inputString("Type of customer: ");
        double customerDiscount = inputDouble("Discount (e.g. 5%): ");
        discountCtr.addCustomerDiscount(type, customerDiscount);
        print(" -> Discount for "+type+" customers applied.");
    }
    
    public void getCustomerDiscount()
    {
        String type = inputString("Type of customer: ");
        double custDisc = discountCtr.getCustomerDiscount(type);
        if(custDisc!=-1)
        {
            print("Discount for "+type+" customer is "+custDisc+"%");
        }
        else print(" -> This type of customer does not exist.");
    }
        
    public void removeDiscount()
    {
        if(!haveAccess()) return;
        String type = inputString("Type of customer: ");
        if (discountCtr.removeCDiscount(type)) print(" -> The discount has been removed.");
        else print(" -> This type of customer does not exist.");
    }
     
    public void setPickupDiscount()
    {
        if(!haveAccess()) return;
        double pickupDiscount = inputDouble("Discount (e.g. 4%): ");
        discountCtr.addPickupDiscount(pickupDiscount);
        print(" -> The delivery discount was applied.");
    }
    
    public void getPickupDiscount()
    {
        double pickDisc = discountCtr.getPickupDiscount("y");
        print("The delivery discount is "+pickDisc+"%");
    }
}
